import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by wuzhao on 2017/3/13 0013.
 */
public class Leetcode {

    public static void main(String[] args) {

        int[] ints = twoSum();
        System.out.printf("==="+ Arrays.toString(ints));
    }

    public static int[] twoSum() {

        //parameter
        int[] numbers = {1,2,4,5};
        int target = 7;

        int[] result = new int[2];
        HashMap<Integer,Integer> map = new HashMap<Integer, Integer>();
        for (int i = 0;i<numbers.length;i++){
            if (map.containsKey(target - numbers[i])){
                result[0] = map.get(target - numbers[i]);
                result[1] = i;
            }
            map.put(numbers[i],i);
        }
        return result;
    }
}
